package com.app.repository.impl;

import com.app.model.main.Approval;
import com.app.repository.interfaces.ApprovalMapper;
import com.app.support.dao.MybatisDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Lichaojie on 2017/3/12. It's a beautiful day.
 */
@Repository
public class ApprovalMapperImpl implements ApprovalMapper {

    @Autowired
    private MybatisDao mybatisDao;

    @Override
    public int deleteByPrimaryKey(Long id){
        return mybatisDao.delete("com.app.dao.main.ApprovalMapper",".deleteByPrimaryKey",id);
    }

    @Override
    public int insert(Approval record){
        return mybatisDao.insert("com.app.dao.main.ApprovalMapper", ".insert", record);
    }

    @Override
    public int insertSelective(Approval record){
        return mybatisDao.insert("com.app.dao.main.ApprovalMapper",".insertSelective",record);
    }

    @Override
    public Approval selectByPrimaryKey(Long id){
        return mybatisDao.get("com.app.dao.main.ApprovalMapper", ".selectByPrimaryKey", id);
    }

    @Override
    public int updateByPrimaryKeySelective(Approval record){
        return mybatisDao.update("com.app.dao.main.ApprovalMapper", ".updateByPrimaryKeySelective", record);
    }

    @Override
    public int updateByPrimaryKey(Approval record){
        return mybatisDao.update("com.app.dao.main.ApprovalMapper",".updateByPrimaryKey",record);
    }

    @Override
    public Approval selectByParam(long userId, String time){
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("time",time);
        return mybatisDao.get("com.app.dao.main.ApprovalMapper", ".selectByParam", map);
    }

    @Override
    public long getApprovalNumber(Long objectId,byte type){
        Map<String,Object> map = new HashMap<>();
        map.put("objectId",objectId);
        map.put("type",type);
        return mybatisDao.count("com.app.dao.main.ApprovalMapper",".getApprovalNumber",map);
    }

    @Override
    public Approval getFlagWithParam(long userId, long objectId, byte type){
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("objectId",objectId);
        map.put("type",type);
        return mybatisDao.get("com.app.dao.main.ApprovalMapper",".getFlagWithParam",map);
    }

    @Override
    public List<Approval> getListByUserIdBetween(long userId, String time1, String time2){
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("time1",time1);
        map.put("ttme2",time2);
        return mybatisDao.getList("com.app.dao.main.ApprovalMapper",".getListByUserIdBetween");
    }

}
